package com.hs.utils;

import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * @author hs
 **/
@Data
public class ResultResponse<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer code;
    private String msg;
    private T data;

    private ResultResponse() {
    }

    private ResultResponse(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResultResponse<?> ok() {
        return new ResultResponse<>(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), null);
    }

    public static <T> ResultResponse<T> ok(T data) {
        return new ResultResponse<>(HttpStatus.OK.value(),HttpStatus.OK.getReasonPhrase(), data);
    }

    public static <T> ResultResponse<T> ok(String msg, T data) {
        return new ResultResponse<>(HttpStatus.OK.value(), msg, data);
    }

    public static <T> ResultResponse<T> fail(String msg) {
        return new ResultResponse<>(HttpStatus.NOT_ACCEPTABLE.value(), msg, null);
    }

    public static <T>ResultResponse<T> fail(int errorCode, String msg) {
        return new ResultResponse<>(errorCode, msg, null);
    }

    public static <T> ResultResponse<T> fail(int errorCode, String msg, T data) {
        return new ResultResponse<>(errorCode, msg, data);
    }

}

